Skip to main content

Convex Hull

Smallest convex polygon or polyhedron that contains region of interest.

🎭 Mask options and parameters getConvexHull method
🔎 ROI options and parameters of convexHull accessor

Convex Hull is a way of characterizing the shape of an image by determining which pixels are adjacent to other pixels of the same intensity. This is a good way to find convex features in an image.

Image input

tip

To understand what convex hull is, picture a rubber band wrapped around your object. The shape of this rubber band will be the shape of your convex hull.

In ImageJS convex hull is a ROI class accessor that returns a ConvexHull object.

Property nameDescriptionProperty type
pointspoints that form convex hullPoint[]
surfaceconvex hull's surfacenumber
perimeterconvex hull's perimeternumber
const convexHull = roi.convexHull;

It can also be a Mask method to calculate its convex hull:

const convexHull = mask.getConvexHull();
Implementation

Here's how convex hull algorithm is implemented in ImageJS:

Calculate border points: ImageJS uses an algorithm to identify points that constitute regions' borders.

Sorting points lexicographically: After finding border points, they get sorted in ascending order.

Build the lower hull: Traverse the sorted list of points to build the lower hull of the convex hull. Use a stack to keep track of the points in the lower hull. For each point, check whether it forms a left or right turn with the previous two points in the stack. If it forms a right turn, pop the last point from the stack until a left turn is formed. Then push the current point onto the stack.

Build the upper hull: Traverse the sorted list of points in reverse order to build the upper hull of the convex hull. Use the same stack as before. Again, ensure that the points in the stack form a convex hull.

Combine the lower and upper hulls: The combined result of the lower and upper hulls is the convex hull of the entire set of points.